from machine import Pin, ADC
import time

"""
土壤湿度传感器
"""

soil_pin = ADC(Pin(26))

time_avg = 10

max_v = 65535


def convert(iv):
    diff = (max_v - iv) / max_v
    return round(diff * 100, 2)


def read_humidity():
    v = 0
    for i in range(time_avg):
        v = v + soil_pin.read_u16()
        time.sleep(0.1)
    return convert(v / time_avg)
